package com.xs.serviceimpl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


import com.xs.bean.VideoTableBean;
import com.xs.dao.VideoDao;
import com.xs.daoimpl.VideoDaoImpl;
import com.xs.service.VideoService;

public class VideoServiceImpl implements VideoService {
	VideoDao vs;

	public VideoServiceImpl() {
		vs = new VideoDaoImpl();
	}

	// 获得video_user_id,即该老师菜单下的所有信息
	@Override
	public List getVideoInfoByUserId(int videoUserId) {
		return vs.getVideoInfoByUserId(videoUserId);
	}

	// 获得当前video
	@Override
	public VideoTableBean getVideoInfoById(int videoId) {
		return vs.getVideoInfoById(videoId);
	}

	//添加上传的视频到sql里面
	@Override
	public boolean uploadVideo(String pageName,String videoName, int videoType, String videoMsg, String videoImgUrl, int userId) {
		//将所得的属性全部set到vb里面再调入方法添加
		VideoTableBean vb=new VideoTableBean();
		vb.setVideoName(pageName);
		vb.setVideoImgUrl("images/"+videoImgUrl);  //添加缩略图路径
		vb.setVideoMsg(videoMsg);
		vb.setVideoUserId(userId);
		vb.setVideoMajorId(videoType);
		//上传视频的时间
		Date   date=new Date();
		SimpleDateFormat  sdf=new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
		vb.setVideoUploadTime(sdf.format(date));  //有参构造函数方法set上传时间--VideoTableBean
		//视频路径通过name更改格式后缀
		videoName=videoName.split("\\.")[0];	//以.开始,取前面名字
		videoName=videoName+".flv";		//加后缀格式
		vb.setVideoUrl("videos/"+videoName);//添加视频路径
		
		return vs.uploadVideo(vb);
	}

}
